* ===============================

* Title: Replication files for 'Analyzing International Organizations: How the Concepts We Use Affect the Answers We Get'
* Project: Re-analysis of Greenhill ISQ 2010
* Author: Charles B. Roger; Sam S. Rowan
* Contact: croger@ibei.org; sam.rowan@concordia.ca
* Date: 1 April 2021

* ===============================

**** Set working directory ****

* Set working directory to 'Roger and Rowan RIO 2021' on your machine


* ===============================
**** Load in Greenhill replication data, merge IO context, and prepare for analysis ****
* ===============================

** This is Greenhill's original dataset from the Dataverse: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/40FMWG
use "data/input/greenhill_isq.dta", replace

* Transform and rename variables as per Greenhill
gen loggdp=log(gdp)
rename polity2 polity
rename fdiin fdi
gen greenhill_io_context = igoc

** Sample composition in Greenhill's main model
tsset bricode year 
qui reg physint L.(igoc physint polity trade fdi loggdp civwar intwar durable density hardpta softpta neighbour language colonies)
gen in_greenhill_t2m1 = e(sample) /* Sample composition */

** Clean data for merging in the IO context variables
* duplicates list ccode year /* Remove duplicate observations that prevent merging: essentially, duplicate observations */
drop if ccode == .
drop if ccode == 345 & igoc == . 
drop if ccode == 255 & igoc == .
drop if ccode == 255 & physint == .
drop if ccode == 365 & igoc == .
replace ccode = 816 if ccode == 817 /* Vietnam */ 

** Merge in IO context data
merge 1:1 ccode year using "data/input/context_v3.dta", gen(_m1)

* =============================== 
**** Re-analyze the data with new IO context variable **** 
* =============================== 

* Set panel data for lagging variables more easily
tsset ccode year

** Original model from ISQ paper
oprobit physint L.greenhill_io_context L.(physint fdi trade density polity durable language colonies neighbour hardpta softpta civwar intwar loggdp) if in_greenhill_t2m1 == 1, robust cluster(ccode)

** Main models
* =============================== 

** Set new working directory for tables
cd "data/output"

** Loop through new IO context variables

foreach var of varlist greenhill_io_context formal_io_context_v3 informal_io_context_v3 total_io_context_v3 {
	qui oprobit physint L.`var' L.(physint fdi trade density polity durable language colonies neighbour hardpta softpta civwar intwar loggdp) if in_greenhill_t2m1 == 1, robust cluster(ccode)
	outreg2 using greenhill_table1_main, se tex dec(3) append 10pct e(r2_p, ll, N_clust) label
}

* ===============================
**** Standardized effects for the different IO variables ****
* ===============================

** Create standardized versions of the key IO variables 

egen z_greenhill = std(greenhill_io_context)
egen z_formal = std(formal_io_context_v3)
egen z_informal = std(informal_io_context_v3)
egen z_total = std(total_io_context_v3)

** Re-run the models

qui oprobit physint L.z_greenhill L.(physint fdi trade density polity durable language colonies neighbour hardpta softpta civwar intwar loggdp) if in_greenhill_t2m1 == 1, robust cluster(ccode)
est store greenhill_greenhill

qui oprobit physint L.z_formal L.(physint fdi trade density polity durable language colonies neighbour hardpta softpta civwar intwar loggdp) if in_greenhill_t2m1 == 1, robust cluster(ccode)
est store greenhill_formal

qui oprobit physint L.z_informal L.(physint fdi trade density polity durable language colonies neighbour hardpta softpta civwar intwar loggdp) if in_greenhill_t2m1 == 1, robust cluster(ccode)
est store greenhill_informal

qui oprobit physint L.z_total L.(physint fdi trade density polity durable language colonies neighbour hardpta softpta civwar intwar loggdp) if in_greenhill_t2m1 == 1, robust cluster(ccode)
est store greenhill_total


** Save the outputs to disk

esttab greenhill_greenhill greenhill_formal greenhill_informal greenhill_total using greenhill_esttab.csv, replace se nostar plain keep(L.z_greenhill L.z_formal L.z_informal L.z_total)
 
* =============================== * =============================== * =============================== * ===============================
* END.
* =============================== * =============================== * =============================== * ===============================

